import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/pages/notice/model/notice_model_entity.dart';
import 'package:flutter/material.dart';
import 'package:get/get_state_manager/src/simple/get_state.dart';
import 'package:get/get_state_manager/src/simple/get_view.dart';
import '../../../components/base/base_nav_bar.dart';
import '../controller/notice_ctr.dart';

class NoticePage extends GetView<NoticeCtr> {
  const NoticePage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<NoticeCtr>(builder: (controller) {
      return BasePage(
        title: '消息中心',
        refreshController: controller.baseRefreshCtr,
        enablePullDown: true,
        enablePullUp: controller.hasNextPage,
        onPageRefresh: controller.onPageRefresh,
        onPageLoading: controller.onPageLoading,
        iconType: IconType.back,
        bodyColor: Colors.white,
        children: [
          ListView.builder(
              itemCount: controller.dataList.length,
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: (context, index) {
                final model = controller.dataList[index];
                return noticeItem(model);
              }),
        ],
      );
    });
  }

  Widget noticeItem(NoticeModelEntity model) {
    return Container(
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.symmetric(vertical: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: 5,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Row(
        children: [
          Container(
            padding: const EdgeInsets.all(5),
            child: Image.asset(
              'assets/images/placeholder_notice.png',
              height: 24,
              width: 24,
            ),
          ),
          const SizedBox(width: 10),
          Expanded(
            child: Text(
              '${model.title}\n${model.pushTime}\n${model.content}',
              style: const TextStyle(
                color: Colors.black,
                fontSize: 14,
                height: 1.5,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
